package com.bdqn.design.proxy.jdk;

import java.lang.reflect.Proxy;

/**
 * IntermediaryJDKProxyFactory 事务，代理工厂
 *
 * @author LILIBO
 * @since 2023-10-10
 */
public class TransactionJDKProxyFactory {

    /**
     * 工厂方法
     *
     * @param target 需要被代理的目标对象
     * @param <T>
     * @return 返回生成好的代理对象
     */
    public static <T> T create(Object target) {
        TransactionInvocationHandler handler = new TransactionInvocationHandler();
        handler.setTarget(target);
        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), handler);
    }

}
